<?php
function curPageURL() {
 $pageURL = 'http';
 if (isset($_SERVER["HTTPS"])) {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"];//.$_SERVER["REQUEST_URI"];
 }
 $pageURL .= $_SERVER["SCRIPT_NAME"];
 return $pageURL;
}
require_once "./lib/DBManager.php";
$dbmanager=new DBManager;
$action=$_GET["action"];
if($action=="create"){
	
	$id=$dbmanager->createPlan($_GET["name"]);
	header('Location: '.curPageURL().'?action=edit&planid='.$id);
	return;
}
if($action=="edit"){	
	$plan=$dbmanager->getPlan($_GET["planid"]);
	
	$content_data["plan_details_ds"]=$plan["plan_details"];
	$content_data["plan_header"]=$plan["plan_header"];
	$content_data["units_ds"]=$dbmanager->getAllUnits();
	$content_data["content_page"]="page/plan_page.php";
	include "base.php";
}
//echo(curPageURL());
//print_r($_SERVER);

?>